package com.example.dou2204.register;

import androidx.lifecycle.MutableLiveData;

import com.example.dou2204.baseMVVM.BaseViewModel;
import com.example.dou2204.entity.UserEntity;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RegisterViewModel extends BaseViewModel<RegisterRepo> {
    @Override
    protected RegisterRepo createRepo() {
        return new RegisterRepo();
    }

    public MutableLiveData<UserEntity> success = new MutableLiveData<>();
    public MutableLiveData<String> fail = new MutableLiveData<>();

    public void register(String username,String password,String repassword){
        Map<String,String> map = new HashMap<>();
        map.put("username",username);
        map.put("password",password);
        map.put("repassword",repassword);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), s);
        repo.register(body,success,fail);
    }
}
